package com.appkubes.mall.admin.application.user.user.service.impl;

import com.appkubes.mall.admin.application.user.user.dao.UserDao;
import com.appkubes.mall.admin.application.user.user.entity.model.GetListResult;
import com.appkubes.mall.admin.application.user.user.service.UserService;
import com.appkubes.mall.core.entity.MallAdmin;
import com.appkubes.mall.core.entity.MallUser;
import com.appkubes.mall.core.service.impl.BaseMallUserServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


@Service
public class UserServiceImpl extends BaseMallUserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    public PageInfo getList(String appKey, String name, int page, int limit) {
        List<GetListResult> list = userDao.getListData(appKey, name, (page - 1) * limit, limit, false);
        PageInfo pageInfo = new PageInfo(list);
        pageInfo.setPageNum(page);
        pageInfo.setPageSize(limit);
        int count = 0;
        List<GetListResult> totalList = userDao.getListData(appKey, name, 0, 0, true);
        if (totalList != null) count = totalList.get(0).getTotal();
        pageInfo.setTotal(count);
        return pageInfo;
    }


    public MallUser getUserByTel(String tel) {
        MallUser query = new MallUser();
        query.setTel(tel);
        List<MallUser> list = this.selectListByEntity(query);
        if (list.size() == 0) return null;
        return list.get(0);
    }


    public Integer countLog(String queryStr) {
        int count = 0;
        String countLog = userDao.countLog(queryStr);
        if (!StringUtils.isEmpty(countLog)) count = Integer.parseInt(countLog);
        return count;
    }


    public Integer countUnBuyUser(List<String> list, String appKey) {
        int count = 0;
        if (list.size() == 0) return count;
        String countLog = userDao.countUnBuyUser(list, appKey);
        if (!StringUtils.isEmpty(countLog)) count = Integer.parseInt(countLog);
        return count;
    }

    @Override
    public String queryCidByTel(String tel) {
        return userDao.queryCidByTel(tel);
    }

    /**
     * 保存商铺信息、个人信息
     * @param mallAdmin
     * @return
     */
    @Override
    public int modify(MallAdmin mallAdmin){
        System.out.println("进来了");
        List<MallUser> result = userDao.ddda(mallAdmin);
        for (int i = 0;i<result.size();i++){
            System.out.println(result.get(i));
        }
        System.out.println("执行完成");
        return 0;
    }
}
